<template>
	<view>
		<uni-group title="医生列表">
			<uni-card>
				<view @click="dianji(index)">
					<view class=" user-box u-p-l-30 u-p-r-20 u-p-b-30 u-border-bottom u-padding-top-10"
						style="display: flex;">
						<view class="u-m-r-10">
							<u-avatar :src="base+item.avatar" size="100"></u-avatar>
						</view>
						<view class="u-flex-1">
							<view class="u-font-18 u-p-b-20">{{item.name}}</view>
							<view class="u-font-18 u-p-b-20">职称:{{item.jobName}}</view>
							<view class="u-font-18 u-p-b-20">执业编号:{{item.practiceNo}}</view>
							<view class="u-font-18 u-p-b-20">从业年限时间:{{item.workingYears}}</view>
							<view class="u-font-14 u-tips-color">擅长描述:{{item.goodAt}}</view>

						</view>
					</view>
				</view>
			</uni-card>
			<uni-group title="问题描述">
				<uni-easyinput type="textarea" v-model="value" placeholder="输入你的问题" maxlength="150"></uni-easyinput>
			</uni-group>
			<uni-group title="问题图片">
				<uni-file-picker :auto-upload="false" file-mediatype="image" limit="1" @select="select">
				</uni-file-picker>
			</uni-group>
		</uni-group>
		<uni-group style="position: absolute;z-index: 99;right: 0%;bottom: 0%;left: 0%;">
			<button type="primary" @click="fian">提交</button>
		</uni-group>
	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				base: api.baseurl,
				item: [],
				value: '',
				img: ''
			}
		},
		onLoad() {
			this.item = uni.getStorageSync('wen')
		},
		methods: {
			select(e) {
				console.log(e.tempFilePaths[0])
				this.shang(e.tempFilePaths[0])
			},
			shang(e) {
				let token = uni.getStorageSync('token')
				uni.uploadFile({
					url: this.base + '/prod-api/common/upload',
					name: 'file',
					filePath: e,
					header: {
						'authorization': token
					},
					success: (res) => {
						let date = JSON.parse(res.data)
						this.img ='/prod-api'+ date.fileName
					}
				})
			},
			fian() {
				if (this.value == '') {
					uni.showToast({
						title: '请输入内容',
						icon: 'none'
					})
					return
				}
				this.$post(this.base + '/prod-api/api/pet-hospital/inquiry', {
					"doctorId": this.item.id,
					"question": this.value,
					"imageUrls": this.img
				}).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '提交成功'
						})
						setTimeout(() => {
							uni.redirectTo({
								url:'index'
							})
						}, 500)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
